home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / System / Docu / Files (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  25.4 KB  |  392 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. HostPictures.StdViewDesc
  23. Geneva
  24. Dialog
  25. Views
  26. Files
  27. Ports
  28. Domains
  29. Fonts
  30. Stores
  31. Models
  32. Controllers
  33. Geneva
  34. Geneva
  35. riders
  36. at beginning
  37. at pos = 5
  38. at end
  39. Geneva
  40. 5.2 Files
  41. DEFINITION Files;
  42.     CONST exclusive = FALSE; shared = TRUE;
  43.     TYPE
  44.         Name = ARRAY 32 OF CHAR;
  45.         Type = ARRAY 8 OF CHAR;
  46.         Locator = POINTER TO LocatorDesc;
  47.         LocatorDesc = RECORD
  48.             res: LONGINT;
  49.             PROCEDURE (l: Locator) This (path: ARRAY OF CHAR): Locator
  50.         END;
  51.         File = POINTER TO FileDesc;
  52.         FileDesc = RECORD
  53.             type-: Type;
  54.             PROCEDURE (f: File) Length (): LONGINT;
  55.             PROCEDURE (f: File) NewReader (old: Reader): Reader;
  56.             PROCEDURE (f: File) NewWriter (old: Writer): Writer;
  57.             PROCEDURE (f: File) Flush;
  58.             PROCEDURE (f: File) Register (name: Name; type: Type; VAR res: LONGINT);
  59.             PROCEDURE (f: File) Close;
  60.             PROCEDURE (f: File) InitType (type: Type)
  61.         END;
  62.         Reader = POINTER TO ReaderDesc;
  63.         ReaderDesc = RECORD
  64.             eof: BOOLEAN;
  65.             PROCEDURE (r: Reader) Base (): File;
  66.             PROCEDURE (r: Reader) Pos (): LONGINT;
  67.             PROCEDURE (r: Reader) SetPos (pos: LONGINT);
  68.             PROCEDURE (r: Reader) ReadByte (VAR x: CHAR);
  69.             PROCEDURE (r: Reader) ReadBytes (VAR x: ARRAY OF CHAR; beg, len: LONGINT)
  70.         END;
  71.         Writer = POINTER TO WriterDesc;
  72.         WriterDesc = RECORD
  73.             PROCEDURE (w: Writer) Base (): File;
  74.             PROCEDURE (w: Writer) Pos (): LONGINT;
  75.             PROCEDURE (w: Writer) SetPos (pos: LONGINT);
  76.             PROCEDURE (w: Writer) WriteByte (x: CHAR);
  77.             PROCEDURE (w: Writer) WriteBytes (VAR x: ARRAY OF CHAR; beg, len: LONGINT)
  78.         END;
  79.         Directory = POINTER TO DirectoryDesc;
  80.         DirectoryDesc = RECORD
  81.             PROCEDURE (d: Directory) This (path: ARRAY OF CHAR): Locator;
  82.             PROCEDURE (d: Directory) Temp (): File;
  83.             PROCEDURE (d: Directory) New (loc: Locator): File;
  84.             PROCEDURE (d: Directory) Old (loc: Locator; name: Name; shared: BOOLEAN): File;
  85.             PROCEDURE (d: Directory) Delete (loc: Locator; name: Name);
  86.             PROCEDURE (d: Directory) Rename (loc: Locator; old, new: Name);
  87.             PROCEDURE (d: Directory) SameFile (loc0: Locator;name0: Name;
  88.                                                                         loc1: Locator; name1: Name): BOOLEAN;
  89.         END;
  90.     VAR dir-, stdDir-: Directory;
  91.     PROCEDURE SetDir (d: Directory);
  92. END Files.
  93. Most programmers never need to deal with files directly, instead they can use readers and writers (of module Stores -> 5.4) which are set up already by Oberon!
  94. Module Files provides the abstractions necessary to handle most aspects of a hierarchical file system. A file is a sequence of bytes. Several access paths can be open simultaneously on the same file, possibly at different positions.
  95. A file and its access paths are modeled as separate data structures, namely as File and Reader/Writer. Where a statement applies both to readers and writers, the term "rider" will be used. An open rider is never closed explicitly, and an application can create as many riders as it needs.
  96. Picture 5.2a  File with three Riders
  97. Each file resides at some location in the file hierarchy (i.e. in a subdirectory). In Oberon, a location is described by a locator object. A directory object provides a procedure which creates a locator, given a path name in the host platform's file name syntax. Most other directory operations take a locator as parameter, to find the specific subdirectory where the operation should be performed.
  98. For temporary files, a system-specific (implicit) location is used. Temporary files are used as scratch files, and cannot be registered in the file directory. Module Dialog provides further sources for file locators, via standard file dialogs.
  99. A file itself is specified by a location and a name. The name is the file's local name at the given location, i.e. it cannot be a path name.
  100. A directory object provides three procedures to access a file: New, Temp, and Old. New creates a new file. This file already has a particular location, but is anonymous, i.e. it has no name (yet). When the file's contents are written, the file can be registered under a given name, possibly replacing an already existing file which in turn becomes anonymous itself. File registration is an atomic action, which reduces the danger that a file is replaced by a new, but incomplete or corrupted, file.
  101. Anonymous files for which no more riders exist are automatically deleted by the garbage collector, at an appropriate time.
  102. Temp creates a temporary file. Such a file is never registered, and thus remains anonymous.
  103. Old looks up and opens an existing file, given its name and location. The file may either be opened in shared or in exclusive mode. "shared" means that it may be looked up and opened by several programs simultaneously, but that none may alter it (immutable file). Even if a file has been opened, its entry in the file directory is replaced when a new file is registered at the same location and under the same name. In this case, the old file remains accessible through the existing file readers. However, looking up this file with procedure Old yields the most recently registered file version. When no more riders on an older file version exist, the disk space occupied by the file is reclaimed by the garbage collector eventually.
  104. Opening a file in shared mode is the rule in Oberon; opening a file in exclusive mode is an infrequent exception. "exclusive" means that at most one program may open a file. As long as the file is not closed again, other programs remain locked out, i.e. Old on the same file fails. An exclusively opened file may be modified (mutable file), which is useful for simple data base applications. Registering a new file under the same name as an exclusively opened file has the same effect as for shared files, i.e. the existing file becomes anonymous, and is garbage collected eventually.
  105. A file can be opened in exclusive mode, closed, and then be opened again in shared mode, for example. However, it can never be open in exclusive and in shared mode simultaneously.
  106. Open files for which no more riders exist are automatically closed by the garbage collector at an appropriate time. For files opened in exclusive mode, it is recommended that they be closed explicitly, in order to make them accessible again to other programs as early as possible.
  107. A directory object represents all accessible files (not just one subdirectory), independent of their location in the file hierarchy. There is exactly one file hierarchy. However, every Oberon service may implement its own file directory object. Such an object represents exactly the same file hierarchy, but may provide different ways to look up files, e.g. by applying default search paths, or it may define a current directory relative to which path names are evaluated, etc.
  108. CONST exclusive, shared
  109. Values which can be passed to the Directory.Old.shared parameter, to determine whether a file should be opened in shared or in exclusive mode.
  110. TYPE Name
  111. String type for file names.
  112. TYPE Type
  113. String type for file type names.
  114. TYPE Locator
  115. Interface
  116. A file locator identifies a location in the file system.
  117. File locators are used internally, and sometimes in commands which operate on non-Oberon files.
  118. File locators are extended internally.
  119. res: LONGINT
  120. Directory operations return their results in the locator's res field.
  121. The following result codes are predefined:
  122. res = 0    no error
  123. res = 1    invalid parameter (name or locator)
  124. res = 2    location or file not found
  125. res = 3    file already exists
  126. res = 4    write-protection
  127. res = 5    io error
  128. res = 6    access denied
  129. res = 7    illegal file type
  130. res = 8    cancelled
  131. A particular Oberon implementation may return additional, platform-specific, error codes. These error codes always have negative values.
  132. PROCEDURE (l: Locator) This (path: ARRAY OF CHAR): Locator
  133. Interface
  134. This evaluates a relative path, starting from the location specified by l.
  135. path # NIL    20
  136. result # NIL
  137.     l.res = 0    no error
  138. result = NIL
  139.     l.res = 1    invalid name
  140.     l.res = 2    location or file not found
  141.     l.res = 4    write-protection
  142.     l.res = 5    io error
  143. TYPE File
  144. Interface
  145. A file is a carrier for a linear sequence of bytes, which typically resides on a hard disk or similar device.
  146. Files are allocated by file directories.
  147. Files are used by commands which operate on non-Oberon files.
  148. Files are extended internally.
  149. type-: Type
  150. This file's file type.
  151. PROCEDURE (f: File) Length (): LONGINT
  152. Interface
  153. Returns the current length of the file in bytes.
  154. result >= 0
  155. PROCEDURE (f: File) NewReader (old: Reader): Reader
  156. Interface
  157. Returns a reader which has the appropriate type (for this file type). If old = NIL, then a new reader is allocated. If old # NIL and old has the appropriate type, old is returned. Otherwise, a new reader is allocated. The returned reader is connected to f, its eof field is set to FALSE, and its position is somewhere on the file. If an old reader is passed as parameter, the old position will be retained if possible.
  158. If an old reader is passed as parameter, it is the application's responsibility to guarantee that it is not in use anymore. Passing an unused old reader is recommended because it avoids unnecessary allocations.
  159. result # NIL
  160. ~result.eof
  161. old # NIL & old.Base() = f
  162.     result.Pos() = old.Pos()
  163. old = NIL OR old.Base() # f
  164.     result.Pos() = 0
  165. PROCEDURE (f: File) NewWriter (old: Writer): Writer
  166. Interface
  167. Returns a writer which has the appropriate type (for this file type). If old = NIL, then a new writer is allocated. If old # NIL and old has the appropriate type, old is returned. Otherwise, a new writer is allocated. The returned writer is connected to f, and its position is somewhere on the file. If an old writer is passed as parameter, the old position will be retained if possible.
  168. If an old writer is passed as parameter, it is the application's responsibility to guarantee that it is not in use anymore. Passing an unused old writer is recommended because it avoids unnecessary allocations.
  169. Read-only files allow no writers at all. In such cases, NewWriter returns NIL.
  170. result # NIL
  171.     old # NIL & old.Base() = f
  172.         result.Pos() = old.Pos()
  173.     old = NIL OR old.Base() # f
  174.         result.Pos() = f.Length()
  175. result = NIL
  176.     read-only file
  177. PROCEDURE (f: File) Flush
  178. Empty
  179. To guarantee consistency of the file, Flush should be called after the last writer operation. Superfluous calls of Flush have no effect.
  180. Close may call Flush internally.
  181. PROCEDURE (f: File) Register (name: Name; type: Type; VAR res: LONGINT)
  182. Interface
  183. Register makes an anonymous file permanently available. If a file with the same name at the same location already exists, it is deleted first. Register can be considered as an atomic action.
  184. Only files opened with procedure New may be registered. Trying to register a file opened with Old results in a precondition violation error.
  185. If an already existing file is deleted during Register, only its entry in the file directory is removed. The file's contents are still available to existing file riders. The space occupied by a file is reclaimed at an unspecified time after no more riders on it exist anymore.
  186. The file f and the riders operating on file f are not valid anymore after registering f, i.e. no more file or rider operations may be performed on it. However, the registered file can be retrieved by procedure Old again.
  187. Register may call Flush internally, and closes the file.
  188. Each registered file has a file type, which is passed to Register in the type parameter. The empty string can be passed, resulting in the standard document file type of Oberon.
  189. f is anonymous and not temporary    20
  190. name # ""    21
  191. name is not a file name    22
  192. res = 0    no error
  193. res = 2    location not found
  194. res = 4    write-protection
  195. res = 5    io error
  196. res = 7    illegal file type
  197. res = 8    cancelled
  198. PROCEDURE (f: File) Close
  199. Interface
  200. Closes an open file. Close does nothing if the file is not open or if it has been opened in "shared" mode. If a call to New or Old is not balanced by a call to Close, the Close is later performed automatically, at an unspecified time. If it is known that a file won't be used again, it is recommended to call its Close procedure.
  201. The file f and the riders operating on file f are not valid anymore after closing f, i.e. no more file or rider operations may be performed on it. However, the closed file can be retrieved and opened again by procedure Old.
  202. Close may call Flush internally.
  203. Close should (but need not necessarily) be called explicitly after a file is not needed anymore.
  204. PROCEDURE (f: File) InitType (type: Type)
  205. Initializes the file's type field.
  206. type # ""    20
  207. f.type = ""    21
  208. TYPE Reader
  209. Interface
  210. Reading access path to a file carrier.
  211. Readers are allocated by their base files.
  212. Readers are used by commands which read non-Oberon files and operate at the byte level.
  213. Readers are extended internally.
  214. eof: BOOLEAN
  215. Set when it has been attempted to read the byte after the end of the file (by ReadByte or ReadBytes). Reset when the reader is generated or positioned.
  216. PROCEDURE (r: Reader) Base (): File
  217. Interface
  218. Returns the file to which the reader is currently connected.
  219. result # NIL
  220. PROCEDURE (r: Reader) Pos (): LONGINT
  221. Interface
  222. Returns the reader's current position.
  223. 0 <= result <= r.Base().Length()
  224. PROCEDURE (r: Reader) SetPos (pos: LONGINT)
  225. Interface
  226. Sets the reader's current position to pos and clears the eof flag.
  227. pos >= 0    20
  228. pos <= r.Base().Length()    21
  229. r.Pos() = pos
  230. ~r.eof
  231. PROCEDURE (r: Reader) ReadByte (VAR x: CHAR)
  232. Interface
  233. Attempts to read the byte after the current position. If successful, it increments the position by one. If the current position (before reading) is at the end of the available data, i.e. Pos equals the carrier data's length, then r.eof is set.
  234. ReadByte internally may call SetPos.
  235. r.Pos()' < r.Length()
  236.     r.Pos() = r.Pos()' + 1
  237.     ~r.eof
  238.     x = byte after r.Pos()'
  239. r.Pos()' = r.Length()
  240.     r.Pos() = r.Length()
  241.     r.eof
  242.     x = 0X
  243. PROCEDURE (r: Reader) ReadBytes (VAR x: ARRAY OF CHAR; beg, len: LONGINT)
  244. Default
  245. Attempts to read len bytes after the current position. It increments the position by the number of bytes which have been read successfully. If reading is continued beyond the file's length, then r.eof is set. The data are transferred to the array x starting at element beg.
  246. ReadBytes is implemented in terms of ReadByte operations, but may be overwritten for efficiency.
  247. ReadBytes internally may call SetPos.
  248. beg >= 0    20
  249. len >= 0    21
  250. beg + len <= LEN(x)    22
  251. r.Pos()' <= r.Length() - len
  252.     r.Pos() = r.Pos()' + len
  253.     ~r.eof
  254.     len bytes read after r.Pos()' and transferred into x
  255. r.Pos()' > r.Length() - len
  256.     r.Pos() = r.Length()
  257.     r.eof
  258.     r.Length() - r.Pos()' bytes read after r.Pos()' and transferred into x
  259. TYPE Writer
  260. Writing access path to a file carrier.
  261. Writers are allocated by their base files.
  262. Writers are used by commands which write non-Oberon files and operate at the byte level.
  263. Writers are extended internally.
  264. PROCEDURE (w: Writer) Base (): File
  265. Interface
  266. Returns the file to which the writer is currently connected.
  267. result # NIL
  268. PROCEDURE (w: Writer) Pos (): LONGINT
  269. Interface
  270. Returns the writer's current position.
  271. 0 <= result <= w.Base().Length()
  272. PROCEDURE (w: Writer) SetPos (pos: LONGINT)
  273. Interface
  274. Sets the writer's current position to pos.
  275. pos >= 0    20
  276. pos <= w.Base().Length()    21
  277. w.Pos() = pos
  278. PROCEDURE (w: Writer) WriteByte (x: CHAR)
  279. Interface
  280. Writes a byte after the current position, then increments the current position. If the current position is at the end of the carrier data, the writer's length is incremented also.
  281. WriteByte internally may call SetPos.
  282. x written at w.Pos()'
  283. w.Pos() = w.Pos()' + 1
  284. w.Pos()' < w.Base().Length()'
  285.     w.Base().Length() = w.Base().Length()'
  286.     x has overwritten old value after w.Pos()'
  287. w.Pos()' = w.Base().Length()'
  288.     w.Base().Length() = w.Base().Length()' + 1
  289.     x was appended
  290. PROCEDURE (w: Writer) WriteBytes (VAR x: ARRAY OF CHAR; beg, len: LONGINT)
  291. Default
  292. Writes len bytes after the current position and increments the position accordingly. If necessary the stream's length is increased. The data are transferred from array x starting with element beg.
  293. WriteBytes is implemented in terms of WriteByte operations, but may be overwritten for efficiency.
  294. WriteBytes internally may call SetPos.
  295. beg >= 0    20
  296. len >= 0    21
  297. beg + len <= LEN(x)    22
  298. len bytes transferred from variable x to carrier
  299. w.Pos() = w.Pos()' + len
  300. w.Pos()' + len <= w.Base().Length()'
  301.     w.Base().Length() = w.Base().Length()'
  302. w.Pos()' + len > w.Base().Length()'
  303.     w.Base().Length() = w.Pos()' + len
  304. TYPE Directory
  305. Interface
  306. Directory for the lookup in and manipulation of file directories.
  307. File directories are allocated by Oberon.
  308. File directories are used by commands which operate on non-Oberon files.
  309. File directories are extended internally.
  310. PROCEDURE (d: Directory) This (path: ARRAY OF CHAR): Locator
  311. Interface
  312. Returns a locator, given a path name in the host platform's syntax.
  313. This may perform some validity checks, e.g. whether the syntax of the name is correct or whether the name denotes an existing subdirectory. Passing the empty string yields a default location.
  314. result # NIL
  315. result.res = 0
  316.     legal locator
  317. result.res # 0
  318.     illegal locator
  319. PROCEDURE (d: Directory) Temp (): File
  320. Interface
  321. Returns a temporary file. This file is anonymous, i.e. not registered in a directory. (In host file systems where anonymous files are not directly supported, they may appear under temporary names in a suitable subdirectory.) Registration is not possible on a temporary file.
  322. A temporary file always has both read and write capabilities (mutable file).
  323. result # NIL
  324. PROCEDURE (d: Directory) New (loc: Locator): File
  325. Interface
  326. Returns a new file object (or NIL if this is not possible). This file is anonymous, i.e. not yet registered in the directory. (In host file systems where anonymous files are not directly supported, they may appear under temporary names in subdirectory loc.) If the file is registered later, it will appear in the subdirectory specified by loc.
  327. A new file always has both read and write capabilities (mutable file).
  328. loc # NIL    20
  329. result # NIL
  330.     loc.res = 0    no error
  331. result = NIL
  332.     loc.res = 1    invalid name
  333.     loc.res = 2    location not found
  334.     loc.res = 4    write-protection
  335.     loc.res = 5    io error
  336. PROCEDURE (d: Directory) Old (loc: Locator; name: Name; shared: BOOLEAN): File
  337. Interface
  338. Looks up and opens a file with name name at location loc. It returns this file (or NIL if this is not possible). Parameter shared determines whether the returned file is in shared or in exclusive mode. A shared file provides read-only access. This means that several applications may read the file simultaneously, but it may not be modified. An exclusively opened file provides exclusive read and write access. This means that both read and write access are denied to any other application. Note however, that the application may pass on the file pointer to wherever it likes. The point is, another application cannot gain access to the file solely via the file directory, without cooperation of the application which currently has access. Moreover, "exclusive" access does not imply that only one rider may be active on the file.
  339. A file is usually opened in shared mode. To change its contents, a new file is generated and then registered under the old name. If only a small part of the data is actually changed, it may be more appropriate to use the exclusive mode instead, e.g. when implementing simple data bases. In this case, the file should be closed explicitly as soon as it isn't needed anymore.
  340. loc # NIL    20
  341. result # NIL
  342.     loc.res = 0    no error
  343. result = NIL
  344.     loc.res = 0    file not found
  345.     loc.res = 1    invalid name
  346.     loc.res = 2    location not found
  347.     loc.res = 6    access denied
  348. PROCEDURE (d: Directory) Delete (loc: Locator; name: Name)
  349. Interface
  350. Deletes the file specified by loc and name.
  351. loc # NIL    20
  352. loc.res = 0    no error
  353. loc.res = 1    invalid parameter (name or locator)
  354. loc.res = 2    location or file not found
  355. loc.res = 4    write-protection
  356. loc.res = 5    io error
  357. PROCEDURE (d: Directory) Rename (loc: Locator; old, new: Name)
  358. Interface
  359. Rename the file specified by loc and new to the local name new. If a file with name new already exists, an error is reported.
  360. loc # NIL    20
  361. loc.res = 0    no error
  362. loc.res = 1    invalid parameter (locator or name)
  363. loc.res = 2    location or file not found
  364. loc.res = 3    file already exists
  365. loc.res = 4    write-protection
  366. loc.res = 5    io error
  367. PROCEDURE (d: Directory) SameFile (loc0: Locator; name0: Name;
  368.                                                                     loc1: Locator; name1: Name): BOOLEAN;
  369. Interface
  370. Determines whether two (locator, name) pairs denote the same file.
  371. loc0 # NIL    20
  372. name0 # ""    21
  373. loc1 # NIL    22
  374. name1 # ""    23
  375. VAR dir-, stdDir-: Directory    (dir # NIL) & (stdDir # NIL)
  376. Directories for the lookup of files.
  377. PROCEDURE SetDir (d: Directory)
  378. Assigns directory.
  379. SetDir is used in configuration routines.
  380. d # NIL    20
  381. stdDir' = NIL
  382.     stdDir = d
  383. stdDir' # NIL
  384.     stdDir = stdDir'
  385. dir = d
  386. TextControllers.StdCtrlDesc
  387. TextControllers.ControllerDesc
  388. Containers.ControllerDesc
  389. Controllers.ControllerDesc
  390. Geneva
  391. Documents.ControllerDesc
  392.